<?php if($isAjax ==0){?>
<div id="tabs">
	<ul>
        <li id="current"><?php echo $this->Html->link(__('Danh sách kênh đã giao cho nhân viên', true), array('controller' => 'z1kenhnvs', 'action' => 'indexcn',$donvicha)); ?> </li>
        <li><?php echo $this->Html->link(__('Danh sách kênh chưa giao cho nhân viên', true), array('controller'=>'kenhs','action' => 'kenhrongcn',$donvicha)); ?></li>
        <li><?php echo $this->Html->link(__('Import kênh mới', true),  array('controller'=>'upfiles','action' => 'add')); ?></li>
	</ul>
	
</div>
<div class="index">
    <h2><?php echo 'Danh sách các kênh đã được giao đơn vị '.$d ['Donvi'] ['tendv'] ?></h2>
    <?php
    echo $form->create('Z1kenhnvs');
    echo '<table>';
    echo '<tr>';
    echo '<td>';
    echo $form->input('loaikenh',array('id'=>'loaikenh','label'=>'Loại kênh','options'=>$loaikenhs,'selected'=>$loaikenh_id));
    echo '</td>';
    echo '<td>';
    echo $form->input('donvi',array('id'=>'donvi','label'=>'Đơn vị','options'=>$donvis,'empty'=>"-- Tất cả --",'selected'=>$donvi_id));
    echo '</td>';
    echo '<td><div id="nv">';
    echo $form->input('nhanvien',array('id'=>'nhanvien','label'=>'Nhân viên','options'=>$nhanviens,'empty'=>"-- Tất cả --",'selected'=>$nhanvien_id));
    echo '</div></td>';
    echo '</tr>';
    echo '</table>';
    echo $form->end();
    ?>
    <div id="danhsach">
    <?php echo $this->Html->link(__('Xuất Excel', true), array('action' => 'indexexcel',$donvicha,$loaikenh_id)); ?>
         
            <table cellpadding="0" cellspacing="0" id="tables" >
	<tr>
			<th><?php echo ('STT');?></th>
            <th><?php echo ('Đơn vị');?></th>
			<th><?php echo 'Nhân viên';?></th>
            <th><?php echo ('Loại kênh');?></th>
			
			<th><?php echo ('Mã kênh');?></th>
			<th><?php echo ('Tên kênh');?></th>
			<th><?php echo ('Địa chỉ');?></th>
			<th><?php echo ('SĐT');?></th>
			<th><?php echo ('Ngày nhận kênh');?></th>
			<th><?php echo ('Lựa chọn');?></th>
	</tr>
	<?php
	$i = 0;
	foreach ($z1kenhnvs as $z1kenhnv):
		$class = null;
		if ($i++ % 2 == 0) {
			$class = ' class="altrow"';
		}
	?>
	<tr<?php echo $class;?>>
		<td><?php echo $i; ?>&nbsp;</td>
        <td>
			<?php echo $z1kenhnv['Donvi']['tendonvi']; ?>
		</td>
		<td>
			<?php echo $z1kenhnv['Nhanvien']['name']; ?>
		</td>
		<td>
			<?php echo $z1kenhnv['Loaikenh']['loaikenh']; ?>
		</td>
		<td><?php echo $z1kenhnv['Z1kenhnv']['makenh']; ?>&nbsp;</td>
		<td><?php echo $z1kenhnv['Z1kenhnv']['tenkenh']; ?>&nbsp;</td>
		<td><?php echo $z1kenhnv['Z1kenhnv']['diachi']; ?>&nbsp;</td>
		<td><?php echo $z1kenhnv['Z1kenhnv']['sdt']; ?>&nbsp;</td>
        
			<td><?php echo date('d-m-Y',strtotime($z1kenhnv['Z1kenhnv']['ngaybd_hd'])); ?>&nbsp;</td>
		<td class="actions">
			<?php //echo $this->Html->link(__('Chi tiết', true), array('controller'=>'congtackenhs','action' => 'index', $z1kenhnv['Z1kenhnv']['id'])); ?>
			<?php echo $this->Html->link(__('Sửa', true), array('controller'=>'kenhs','action' => 'suakenh', $z1kenhnv['Z1kenhnv']['id'])); ?>
			<?php echo $this->Html->link(__('Xóa', true), array('controller'=>'kenhs','action' => 'xoakenh', $z1kenhnv['Z1kenhnv']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $z1kenhnv['Z1kenhnv']['id'])); ?>
		</td>
	</tr>
    <?php endforeach; ?>
	</table>
	<p>
	<?php
	$this->Paginator->options(array('url' => array($donvicha,$loaikenh_id,$donvi_id,$nhanvien_id)));
	echo $this->Paginator->counter(array(
	'format' => __('Trang %page%/%pages%, hiện có %count% mẫu tin', true)
	));
	?>	</p>

	<div class="paging">
		<?php echo $this->Paginator->prev('<< ' . __('Trước', true), array(), null, array('class'=>'disabled'));?>
	 | 	<?php echo $this->Paginator->numbers();?>
 |
		<?php echo $this->Paginator->next(__('Sau', true) . ' >>', array(), null, array('class' => 'disabled'));?>
	</div>
    </div>

<?php
$this->Js->get('#donvi')->event('change',
							$this->Js->request(array('controller' => 'Z1kenhnvs', 'action' => 'indexcn',$donvicha),
							array('update' => '#danhsach','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));
$this->Js->get('#donvi')->event('change',
							$this->Js->request(array('controller' => 'Z1kenhnvs', 'action' => 'dsnv',$donvicha),
							array('update' => '#nv','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));
$this->Js->get('#nv')->event('change',
							$this->Js->request(array('controller' => 'Z1kenhnvs', 'action' => 'indexcn',$donvicha),
							array('update' => '#danhsach','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));
$this->Js->get('#loaikenh')->event('change',
							$this->Js->request(array('controller' => 'Z1kenhnvs', 'action' => 'indexcn',$donvicha),
							array('update' => '#danhsach','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));

?>
 <?php }else{?>
 <?php if (!empty($z1kenhnvs)){?>
  <?php echo $this->Html->link(__('Xuất Excel', true), array('action' => 'indexcnexcel',$donvicha,$loaikenh_id,$donvi_id,$nhanvien_id)); ?>
   
	<table cellpadding="0" cellspacing="0" id="tables">
	<tr>
		    <th><?php echo ('STT');?></th>
            <th><?php echo ('Đơn vị');?></th>
			<th><?php echo 'Nhân viên';?></th>
            <th><?php echo ('Loại kênh');?></th>
			
			<th><?php echo ('Mã kênh');?></th>
			<th><?php echo ('Tên kênh');?></th>
			<th><?php echo ('Địa chỉ');?></th>
			<th><?php echo ('SĐT');?></th>
			<th><?php echo ('Ngày nhận kênh');?></th>
			<th class="actions"><?php __('Lựa chọn');?></th>
	</tr>
	<?php
	$i = 0;
	foreach ($z1kenhnvs as $z1kenhnv):
		$class = null;
		if ($i++ % 2 == 0) {
			$class = ' class="altrow"';
		}
	?>
	<tr<?php echo $class;?>>
		<td><?php echo $i; ?>&nbsp;</td>
        	<td>
			<?php echo $z1kenhnv['Donvi']['tendonvi']; ?>
		</td>
		<td>
			<?php echo $z1kenhnv['Nhanvien']['name']; ?>
		</td>
		<td>
			<?php echo $z1kenhnv['Loaikenh']['loaikenh']; ?>
		</td>
		<td><?php echo $z1kenhnv['Z1kenhnv']['makenh']; ?>&nbsp;</td>
		<td><?php echo $z1kenhnv['Z1kenhnv']['tenkenh']; ?>&nbsp;</td>
		<td><?php echo $z1kenhnv['Z1kenhnv']['diachi']; ?>&nbsp;</td>
		<td><?php echo $z1kenhnv['Z1kenhnv']['sdt']; ?>&nbsp;</td>
	
		<td><?php echo date('d-m-Y',strtotime($z1kenhnv['Z1kenhnv']['ngaybd_hd'])); ?>&nbsp;</td>
		<td class="actions">
			<?php //echo $this->Html->link(__('Chi tiết', true), array('controller'=>'congtackenhs','action' => 'index', $z1kenhnv['Z1kenhnv']['id'])); ?>
			<?php echo $this->Html->link(__('Sửa', true), array('controller'=>'kenhs','action' => 'suakenh', $z1kenhnv['Z1kenhnv']['id'])); ?>
			<?php echo $this->Html->link(__('Xóa', true), array('controller'=>'kenhs','action' => 'xoakenh', $z1kenhnv['Z1kenhnv']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $z1kenhnv['Z1kenhnv']['id'])); ?>
		</td>
	</tr>
<?php endforeach; ?>
	</table>
	<p>
	<?php
	$this->Paginator->options(array('url' => array($donvicha,$loaikenh_id,$donvi_id,$nhanvien_id)));
	echo $this->Paginator->counter(array(
	'format' => __('Trang %page%/%pages%, hiện có %count% mẫu tin', true)
	));
	?>	</p>

	<div class="paging">
		<?php echo $this->Paginator->prev('<< ' . __('Trước', true), array(), null, array('class'=>'disabled'));?>
	 | 	<?php echo $this->Paginator->numbers();?>
 |
		<?php echo $this->Paginator->next(__('Sau', true) . ' >>', array(), null, array('class' => 'disabled'));?>
	</div>
<?php } else echo '<h3>Nhân viên chưa được phân loại kênh này</h3>'; ?>
<?php }?>

</div>
